# # pip install pyjwt
#
# import jwt
#
# data = {
#     'uid': 1
# }
#
# token = jwt.encode(payload=data, key='123').decode()
# # token
# # request.body
# # redis取回来的 bytes
# print(token)
# token1 = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9'
# token2 = 'eyJ1aWQiOjJ9'   #  =>  ''b'eyJ1aWQiOjJ9'
# token3 = '2RlDRxOpLfLP4xGtthS7aJE2N4U5Xydot-XRTIKPGwA'
# token4 = '.'.join([token1, token2, token3])
# print(token4)
# # 把token 返回给前端, 保存到浏览器
# # eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9   =>   b'{"typ":"JWT","alg":"HS256"}'
# # eyJ1aWQiOjF9  =>  b'{"uid":1}'
# # 2RlDRxOpLfLP4xGtthS7aJE2N4U5Xydot-XRTIKPGwA
# # 前端再次请求后端, 需要携带token
# data = jwt.decode(token4, key='123')
# print(data)
# print(data.get('uid'))
#
#
# # 字符串编码
# # unicode   6个16进制   24位二进制,   000000000000000000000000  ->  000100001111111111111111
# # 000000000000000000000000  =>  a
# # 000000000000000000000001  =>  b
# # 000000000000000000000010  =>  c
# # 000000000000000000000010  =>  中
# # 中=>
# # unicode 码 可以代表世界上所有的字符
#
# # utf8  对unicode进行压缩
# # 二进制  bytes类型
# # ascii
# # 如果是bytes类型的数据, 不能直接运算,  python2   系统的默认编码是 ascii, python3  默认编码是  utf8
#
# #python3, 系统默认是utf8,
# # encode()  utf8 =>  其他编码
# # decode()  其他编码  =>  utf8
#
#
# # 1个16进制,  0000 ->0    1111-> F(15)
# # python  string   'abc'  '你好'
#
# # 装饰器
#
#
import datetime
import time

def outer(t):
    def ptime(f):  # 变成另外一个函数(必须和源函数返回同样的结果), 而且不能执行要包装的函数,
        def inner(n):
            print(datetime.datetime.now())
            time.sleep(t)
            res = f(n)
            print(datetime.datetime.now())
            return res
        return inner
    return ptime


def ptime(f):  # 变成另外一个函数(必须和源函数返回同样的结果), 而且不能执行要包装的函数,
    def inner(request):
        print(datetime.datetime.now())
        res = f(request)
        print(datetime.datetime.now())
        return res
    return inner


def func(n):
    return n + 1


def func2(n):
    return n * 2

# @outer(t=3)
@ptime
def func3(a,b):
    return a+b


# func3 = ptime(func3)  # =>   @ptime

func3(2)

from django.utils.decorators import method_decorator


@method_decorator(ptime, 'get')
class A():
    # @method_decorator(ptime)
    def get(self, request):
        pass








